//
//  TopicBannerTableViewCell.swift
//  Venus
//
//  Created by Smith_Yang on 2018/9/14.
//  Copyright © 2018 zhaowang. All rights reserved.
//

import UIKit



protocol  TopicBannerTableViewCellDelegate : class {
    func bannerCycleViewDidScrollToIndex(_ index: Int, view:ZCycleView);
}


class TopicBannerTableViewCell: UITableViewCell {
    
    fileprivate lazy var bannerView =  ZCycleView()
    weak var delegate: TopicBannerTableViewCellDelegate?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK:- 显示数据
extension TopicBannerTableViewCell : ZCycleViewProtocol{
    func cycleViewDidScrollToIndex(_ index: Int) {
        
    }
    
    
    func configModel(model:TopicDetailModel) {
        var bannerArr = [String]()
        let str = model.videoImgPath

        guard let codeUrlStr = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else {return }
        bannerArr.append(codeUrlStr)
        bannerView.setUrlsGroup(bannerArr)
    }
    
    func cycleViewDidSelectedIndex(_ index: Int) {
        delegate?.bannerCycleViewDidScrollToIndex(index,view: self.bannerView)
    }
}

// MARK:- 设置UI
extension TopicBannerTableViewCell {
    fileprivate func setupUI(){
        contentView.addSubview(bannerView)
        bannerView.snp.makeConstraints { (make) in
            make.edges.equalTo(contentView)
        }
        
        bannerView.placeholderImage = UIImage(named: "pic_light")
        bannerView.pageControlItemSize = CGSize(width: 25, height: 2)
        bannerView.pageControlCurrentItemSize = CGSize(width: 25, height: 2)
        bannerView.pageControlAlignment = .center
        bannerView.pageControlIndictirColor = UIColor.init(white: 1, alpha: 0.3)
        bannerView.pageControlCurrentIndictirColor = UIColor.white
        bannerView.timeInterval = 3
        bannerView.delegate = self
    }
}
